<?
	$title="View Offline Purchase";
	
	require("required/dbconnect.php");
	require("required/function.php");	
	require("required/header.php");
	checkAccess("allow_branch_sales_view",1);
	
	if(empty($_GET["id"]))
	{
		errRedirect("2","Invalid Access",$_SERVER['PHP_SELF'],"9");
	}
	
	$id = $_GET["id"];
	
	$get_data=mysql_query("select * from os_offline_purchase where id=$id");
	
	if(mysql_num_rows($get_data)==0){
	 	errRedirect("2","Record not found",$_SERVER['PHP_SELF'],"");		
	}
	
	$a=mysql_fetch_array($get_data,MYSQL_ASSOC);
	
	if($_SESSION['branch_id']!=0 && $a['created_branch_id']!=$_SESSION['branch_id'])
	{
		errRedirect("2","Invalid Access",$_SERVER['PHP_SELF'],"9");
	}

?>
<script src="required/js/jquery-1.4.2.js"></script>
<script src="required/js/common_javascript.js"></script>
<?	
	if(empty($_GET['action']))
	{
		$msg="";
	}
	else
	{
		switch($_GET['action'])
		{
			case "1":
				$msg="<div class='dw_failed'>Email already exist!</div>";
				break;
			case "2":
				$msg="<div class='dw_failed'>Member Card Number already exist!</div>";
				break;
			case "3":
				$msg="<div class='dw_success'>Purchase Created!</div>";
				break;	
			default:
				$msg="";
				break;
		}
		
		echo "<script>displayMsg('divMsg')</script>";	
	}
		
?>	
<table width="100%" cellpadding="0" cellspacing="0" height="100%">

    <td valign="top" align="left">
       <table width="100%">
			
				<tr>
					<td colspan="3" class="title">
				
					Offline Purchase
					
					</td>
				</tr>
                <tr>
                	<td colspan="3"><?= $msg ?></td>
                </tr>
				<tr valign="top">
					<td>Buyer Email</td><td width="84%">
                    	<?= $a['email'] ?> 
                        <?
							if(checkAccess("allow_online_member_view",0))
							{
								if($a['member_id']!=0)
								{
									$get_member=mysql_query("select * from os_member where id=".$a['member_id']);
													
									if(mysql_num_rows($get_member)!=0)
									{
									
										echo "( <a href='member_viewfull.php?id=".mysql_result($get_member,0,"id")."'>".mysql_result($get_member,0,"name")."</a> )";
									}
								}
							}
						?>
                    </td>
			  </tr>
				<tr valign="top">
					<td>Member Card Number</td><td width="84%">
                   <?= $a['member_card_number'] ?>
                    </td>
			  </tr>
			  <tr>
					<td>Receipt Number</td><td width="84%">
                     <?= $a['receipt_number'] ?>
                    
                    </td>
			  </tr>
				<tr>
					<td>Purchase Amount</td><td width="84%">RM 
					  <?= $a['amount'] ?>
                    </td>
			  </tr>
              <tr>
					<td>Purchase Date</td><td width="84%">
					  <?= $a['created_datetime'] ?>
                    </td>
			  </tr>
              <tr>
					<td>Created By</td><td width="84%">
					  <?= getDataById("os_user","user_id","id",$a['created_by']) ?>
                    </td>
			  </tr>
              <tr>
					<td>Branch</td><td width="84%">
					  <?= getDataById("os_branch","branch_name","id",$a['created_branch_id']) ?>
                    </td>
			  </tr>
							
			
				<td width="16%">
				
                <?
					if(checkAccess("allow_branch_sales_delete",0)){
				?>
				  <input type="button" value="Delete" class="button" name="btnsubmit" onclick="window.open('offline_purchase_delete.php?id=<?= $id ?>','_self')">
                 <? } ?>
					<input type="button" value="Back" onclick="window.open('offline_purchase_view_all.php','_self')" />					
                </td>
			</table>
    </td>
</table>					
<?
	require("required/footer.php");
?>               
        